import {
  getEntirDepartments,
  getEntirMenus,
  getEntirRoles
} from '@/service/main/main'
import { defineStore } from 'pinia'

interface IMainState {
  entireRoles: any[]
  entireDepartments: any[]
  entirMenus: any[]
}

const useMainStore = defineStore('main', {
  state: (): IMainState => ({
    entireRoles: [], //获取所有角色
    entireDepartments: [], // 获取所有部门
    entirMenus: [] //获取所有菜单
  }),
  actions: {
    // 获取部门/角色数据
    async fetchEntireDataAction() {
      const rolesResult = await getEntirRoles()
      const departmentsResult = await getEntirDepartments()
      const menuResult = await getEntirMenus()
      // 储存数据
      this.entireRoles = rolesResult.data.list
      this.entireDepartments = departmentsResult.data.list
      this.entirMenus = menuResult.data.list
    }
  }
})

export default useMainStore
